{% extends 'myadmin/base.html' %}

{% block title %}
<title>图书管理</title>
{% endblock %}

{% block content %}
  <!-- content start -->
  <div class="admin-content">
    <div class="admin-content-body">
      <div class="am-cf am-padding am-padding-bottom-0">
        <div class="am-fl am-cf"><strong class="am-text-primary am-text-lg">图书管理</strong> / <small>User Manage</small></div>
      </div>

      <hr>

      <div class="am-g">
        <div class="am-u-sm-12 am-u-md-6">
          <div class="am-btn-toolbar">
            <div class="am-btn-group am-btn-group-xs">
              <button type="button" class="am-btn am-btn-default"><a href="{% url 'myadmin_book_add' %}"> 添加</a></button>
            </div>
          </div>
        </div>
        <form action="" method="GET">
          <!-- 页面搜索功能 -->
          <div class="am-u-sm-12 am-u-md-3">
            <div class="am-form-group">
              <!-- 搜索类别，叫selecttype -->
              <select name="selecttype" data-am-selected="{btnSize: 'sm'}">
                <option value="all" {% if request.GET.selecttype == "all" %} selected {% endif %}>所有类别</option>
                <option value="phonenum" {% if request.GET.selecttype == "phonenum" %} selected {% endif %}>书名</option>
                <option value="nikename" {% if request.GET.selecttype == "nikename" %} selected {% endif %}>作者</option>
                <option value="sex" {% if request.GET.selecttype == "sex" %} selected {% endif %}>价格</option>
              </select>
            </div>
          </div>
          <div class="am-u-sm-12 am-u-md-3">
            <div class="am-input-group am-input-group-sm">
              <!-- 搜索类别，叫selectkey-->
              <input type="text" name="selectkey" value="{{ request.GET.selectkey }}" class="am-form-field">
                <span class="am-input-group-btn">
                  <button class="am-btn am-btn-success" type="button">搜索</button>
                </span>
            </div>
          </div>
        </form>
      </div>

      <div class="am-g">
        <div class="am-u-sm-12">
          <form class="am-form">
            <table class="am-table am-table-striped am-table-hover table-main">
              <thead>
              <tr>
                  <th class="table-check"><input type="checkbox" /></th>
                  <th>ID</th>
                  <th>封面</th>
                  <th>书名</th>
                  <th>简介</th>
                  <th>作者</th>
                  <th>出版社</th>
                  <th>出版时间</th>
                  <th>价格</th>
                  <th>操作</th>
              </tr>
              </thead>
              <tbody>
                {% for i in book_data %}
                <tr>
                  <td><input type="checkbox" /></td>
                  <td>{{ i.id }}</td>
                  <th>
                    <!-- 通过book data实例，找到bookimgs类，然后再找图片地址 -->
                    <img src="/{{ i.bookimgs_set.first.book_img }}" style="width:100px";>
                  </th>
                  <td>{{ i.title }}</td>
                  <td>{{ i.jianjie|truncatechars:50 }}</td>
                  <td>{{ i.author }}</td>
                  <td>{{ i.publisher }}</td>
                  <td>{{ i.pub_date|date:'Y-m-d' }}</td>
                  <td>{{ i.price }}</td>
                  <td>
                    <div class="am-btn-toolbar">
                      <div class="am-btn-group am-btn-group-xs">
                        <button class="am-btn am-btn-default am-btn-xs am-text-secondary"><span class="am-icon-pencil-square-o"></span><a href="{% url 'myadmin_book_edit' %}?id={{ i.id }}">编辑</a></button>
                        <button class="am-btn am-btn-default am-btn-xs am-text-danger am-hide-sm-only"><span class="am-icon-trash-o"></span> 删除</button>
                      </div>
                    </div>
                  </td>
                </tr>
              {% endfor %}
              </tbody>
            </table>
            <div class="am-cf">
              <td>总页数：{{ user_data.paginator.num_pages }}</td>
              <td>总条数：{{ user_data.paginator.count }}</td>
              <div class="am-fr">
                <ul class="am-pagination">
                  <!-- 分页管理 -->
                  {% load pagetag %}
                  <!-- 使用自定义分页标签 -->
                  <!-- 从后端获取user_data数据和request对象，然后调用pageinit自定义标签 -->
                </ul>
              </div>
            </div>
            <hr />
            <p>注：.....</p>
          </form>
        </div>

      </div>
    </div>

    <footer class="admin-content-footer">
      <hr>
      <p class="am-padding-left">© 2014 AllMobilize, Inc. Licensed under MIT license.</p>
    </footer>

  </div>
  <!-- content end -->

<a href="#" class="am-icon-btn am-icon-th-list am-show-sm-only admin-menu" data-am-offcanvas="{target: '#admin-offcanvas'}"></a>

<footer>
  <hr>
  <p class="am-padding-left">© 2014 AllMobilize, Inc. Licensed under MIT license.</p>
</footer>
{% endblock %}


